using DataDynamics.ActiveReports;
using DataDynamics.ActiveReports.Export.Xls;
using SM.core;
using SS;
using System;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Windows.Forms;
using TVSBH.core;
using TVSGPP.tools;
namespace TVSBH.func
{
	public class frmDebtFirstBalancer : Form
	{
		private IContainer components = null;
		private GroupBox groupBox1;
		private System.Windows.Forms.Label label1;
		private DataGridView dgvProduct;
		private Button btnPrint;
		private Button btnClose;
		private System.Windows.Forms.TextBox txtAllMoney;
		private ComboBox cbbObject;
		private Button btnSave;
		private Button btnEdit;
		private Button btnExportToExcel;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.TextBox txtSearch;
		private BindingNavigator bindingNavigator1;
		private ToolStripLabel bindingNavigatorCountItem;
		private ToolStripButton bindingNavigatorMoveFirstItem;
		private ToolStripButton bindingNavigatorMovePreviousItem;
		private ToolStripSeparator bindingNavigatorSeparator;
		private ToolStripTextBox bindingNavigatorPositionItem;
		private ToolStripSeparator bindingNavigatorSeparator1;
		private ToolStripButton bindingNavigatorMoveNextItem;
		private ToolStripButton bindingNavigatorMoveLastItem;
		private ToolStripSeparator bindingNavigatorSeparator2;
		private DataGridViewTextBoxColumn Column7;
		private DataGridViewTextBoxColumn Column2;
		private DataGridViewTextBoxColumn Column5;
		private DataGridViewTextBoxColumn Money;
		private DataGridViewTextBoxColumn CID;
		private DataGridViewTextBoxColumn PID;
		private Button btnHelp;
		private Func objFunc = new Func();
		private DataTable objTable = new DataTable();
		private Bill objBill = new Bill();
		private Partner objPartner = new Partner();
		private bool isPostBack = false;
		protected override void Dispose(bool disposing)
		{
			if (disposing && this.components != null)
			{
				this.components.Dispose();
			}
			base.Dispose(disposing);
		}
		private void InitializeComponent()
		{
			this.components = new Container();
			DataGridViewCellStyle dataGridViewCellStyle = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle2 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle3 = new DataGridViewCellStyle();
			ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof(frmDebtFirstBalancer));
			this.groupBox1 = new GroupBox();
			this.txtSearch = new System.Windows.Forms.TextBox();
			this.label2 = new System.Windows.Forms.Label();
			this.cbbObject = new ComboBox();
			this.label1 = new System.Windows.Forms.Label();
			this.dgvProduct = new DataGridView();
			this.Column7 = new DataGridViewTextBoxColumn();
			this.Column2 = new DataGridViewTextBoxColumn();
			this.Column5 = new DataGridViewTextBoxColumn();
			this.Money = new DataGridViewTextBoxColumn();
			this.CID = new DataGridViewTextBoxColumn();
			this.PID = new DataGridViewTextBoxColumn();
			this.btnPrint = new Button();
			this.btnClose = new Button();
			this.txtAllMoney = new System.Windows.Forms.TextBox();
			this.btnSave = new Button();
			this.btnEdit = new Button();
			this.btnExportToExcel = new Button();
			this.bindingNavigator1 = new BindingNavigator(this.components);
			this.bindingNavigatorCountItem = new ToolStripLabel();
			this.bindingNavigatorMoveFirstItem = new ToolStripButton();
			this.bindingNavigatorMovePreviousItem = new ToolStripButton();
			this.bindingNavigatorSeparator = new ToolStripSeparator();
			this.bindingNavigatorPositionItem = new ToolStripTextBox();
			this.bindingNavigatorSeparator1 = new ToolStripSeparator();
			this.bindingNavigatorMoveNextItem = new ToolStripButton();
			this.bindingNavigatorMoveLastItem = new ToolStripButton();
			this.bindingNavigatorSeparator2 = new ToolStripSeparator();
			this.btnHelp = new Button();
			this.groupBox1.SuspendLayout();
			((ISupportInitialize)this.dgvProduct).BeginInit();
			((ISupportInitialize)this.bindingNavigator1).BeginInit();
			this.bindingNavigator1.SuspendLayout();
			base.SuspendLayout();
			this.groupBox1.Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right);
			this.groupBox1.Controls.Add(this.txtSearch);
			this.groupBox1.Controls.Add(this.label2);
			this.groupBox1.Controls.Add(this.cbbObject);
			this.groupBox1.Controls.Add(this.label1);
			this.groupBox1.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.groupBox1.Location = new System.Drawing.Point(7, 2);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new Size(887, 70);
			this.groupBox1.TabIndex = 1;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "Thông tin tìm kiếm";
			this.txtSearch.Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right);
			this.txtSearch.Font = new Font("Arial", 10f, FontStyle.Bold);
			this.txtSearch.Location = new System.Drawing.Point(384, 27);
			this.txtSearch.Name = "txtSearch";
			this.txtSearch.Size = new Size(485, 23);
			this.txtSearch.TabIndex = 65;
			this.txtSearch.TextChanged += new EventHandler(this.txtSearch_TextChanged);
			this.label2.AutoSize = true;
			this.label2.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.label2.Location = new System.Drawing.Point(297, 31);
			this.label2.Name = "label2";
			this.label2.Size = new Size(83, 15);
			this.label2.TabIndex = 64;
			this.label2.Text = "Tìm theo tên :";
			this.cbbObject.BackColor = Color.White;
			this.cbbObject.DropDownStyle = ComboBoxStyle.DropDownList;
			this.cbbObject.FlatStyle = FlatStyle.Flat;
			this.cbbObject.Font = new Font("Arial", 8.5f);
			this.cbbObject.FormattingEnabled = true;
			this.cbbObject.Items.AddRange(new object[]
			{
				"Khách hàng",
				"Nhà cung cấp"
			});
			this.cbbObject.Location = new System.Drawing.Point(103, 27);
			this.cbbObject.Name = "cbbObject";
			this.cbbObject.Size = new Size(191, 22);
			this.cbbObject.TabIndex = 63;
			this.cbbObject.SelectedIndexChanged += new EventHandler(this.cbbObject_SelectedIndexChanged);
			this.label1.AutoSize = true;
			this.label1.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.label1.Location = new System.Drawing.Point(27, 31);
			this.label1.Name = "label1";
			this.label1.Size = new Size(71, 15);
			this.label1.TabIndex = 62;
			this.label1.Text = "Đối tượng :";
			this.dgvProduct.AllowUserToAddRows = false;
			this.dgvProduct.AllowUserToDeleteRows = false;
			this.dgvProduct.AllowUserToOrderColumns = true;
			this.dgvProduct.AllowUserToResizeColumns = false;
			this.dgvProduct.AllowUserToResizeRows = false;
			dataGridViewCellStyle.BackColor = Color.FromArgb(192, 255, 255);
			dataGridViewCellStyle.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 0);
			this.dgvProduct.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle;
			this.dgvProduct.Anchor = (AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right);
			this.dgvProduct.BackgroundColor = Color.White;
			this.dgvProduct.BorderStyle = BorderStyle.Fixed3D;
			this.dgvProduct.ColumnHeadersHeight = 26;
			this.dgvProduct.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
			this.dgvProduct.Columns.AddRange(new DataGridViewColumn[]
			{
				this.Column7,
				this.Column2,
				this.Column5,
				this.Money,
				this.CID,
				this.PID
			});
			this.dgvProduct.Cursor = Cursors.Hand;
			this.dgvProduct.EnableHeadersVisualStyles = false;
			this.dgvProduct.Location = new System.Drawing.Point(7, 78);
			this.dgvProduct.MultiSelect = false;
			this.dgvProduct.Name = "dgvProduct";
			this.dgvProduct.ReadOnly = true;
			this.dgvProduct.RowHeadersVisible = false;
			this.dgvProduct.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing;
			this.dgvProduct.RowTemplate.DefaultCellStyle.BackColor = Color.White;
			this.dgvProduct.RowTemplate.DefaultCellStyle.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 0);
			this.dgvProduct.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
			this.dgvProduct.Size = new Size(886, 457);
			this.dgvProduct.TabIndex = 3;
			this.Column7.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
			this.Column7.DataPropertyName = "Name";
			dataGridViewCellStyle2.Format = "D";
			dataGridViewCellStyle2.NullValue = null;
			this.Column7.DefaultCellStyle = dataGridViewCellStyle2;
			this.Column7.HeaderText = "Khách hàng";
			this.Column7.MinimumWidth = 300;
			this.Column7.Name = "Column7";
			this.Column7.ReadOnly = true;
			this.Column7.SortMode = DataGridViewColumnSortMode.NotSortable;
			this.Column2.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
			this.Column2.DataPropertyName = "Address";
			this.Column2.HeaderText = "Địa chỉ";
			this.Column2.MinimumWidth = 200;
			this.Column2.Name = "Column2";
			this.Column2.ReadOnly = true;
			this.Column2.SortMode = DataGridViewColumnSortMode.NotSortable;
			this.Column5.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.Column5.DataPropertyName = "Phone";
			this.Column5.HeaderText = "Điện thoại";
			this.Column5.MinimumWidth = 150;
			this.Column5.Name = "Column5";
			this.Column5.ReadOnly = true;
			this.Column5.SortMode = DataGridViewColumnSortMode.NotSortable;
			this.Column5.Width = 150;
			this.Money.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.Money.DataPropertyName = "Money";
			dataGridViewCellStyle3.Alignment = DataGridViewContentAlignment.MiddleRight;
			dataGridViewCellStyle3.Font = new Font("Arial", 9.75f, FontStyle.Bold, GraphicsUnit.Point, 163);
			dataGridViewCellStyle3.ForeColor = Color.Red;
			this.Money.DefaultCellStyle = dataGridViewCellStyle3;
			this.Money.HeaderText = "Dư nợ đầu kỳ";
			this.Money.MinimumWidth = 150;
			this.Money.Name = "Money";
			this.Money.ReadOnly = true;
			this.Money.SortMode = DataGridViewColumnSortMode.NotSortable;
			this.Money.Width = 150;
			this.CID.DataPropertyName = "CID";
			this.CID.HeaderText = "CID";
			this.CID.Name = "CID";
			this.CID.ReadOnly = true;
			this.CID.SortMode = DataGridViewColumnSortMode.NotSortable;
			this.CID.Visible = false;
			this.PID.DataPropertyName = "PID";
			this.PID.HeaderText = "PID";
			this.PID.Name = "PID";
			this.PID.ReadOnly = true;
			this.PID.SortMode = DataGridViewColumnSortMode.NotSortable;
			this.PID.Visible = false;
			this.btnPrint.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left);
			this.btnPrint.Enabled = false;
			this.btnPrint.FlatAppearance.BorderColor = Color.FromArgb(255, 128, 255);
			this.btnPrint.FlatStyle = FlatStyle.Flat;
			this.btnPrint.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnPrint.Location = new System.Drawing.Point(201, 568);
			this.btnPrint.Name = "btnPrint";
			this.btnPrint.Size = new Size(102, 26);
			this.btnPrint.TabIndex = 45;
			this.btnPrint.Text = "Xem và in [ F7 ]";
			this.btnPrint.UseVisualStyleBackColor = true;
			this.btnPrint.Click += new EventHandler(this.btnPrint_Click);
			this.btnClose.Anchor = (AnchorStyles.Bottom | AnchorStyles.Right);
			this.btnClose.FlatAppearance.BorderColor = Color.FromArgb(255, 128, 255);
			this.btnClose.FlatStyle = FlatStyle.Flat;
			this.btnClose.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnClose.Location = new System.Drawing.Point(794, 568);
			this.btnClose.Name = "btnClose";
			this.btnClose.Size = new Size(100, 26);
			this.btnClose.TabIndex = 44;
			this.btnClose.Text = "Thoát  [ ESC ]";
			this.btnClose.UseVisualStyleBackColor = true;
			this.btnClose.Click += new EventHandler(this.btnClose_Click);
			this.txtAllMoney.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right);
			this.txtAllMoney.BackColor = Color.White;
			this.txtAllMoney.Font = new Font("Arial", 9.75f, FontStyle.Bold, GraphicsUnit.Point, 0);
			this.txtAllMoney.ForeColor = Color.Red;
			this.txtAllMoney.Location = new System.Drawing.Point(199, 541);
			this.txtAllMoney.Name = "txtAllMoney";
			this.txtAllMoney.ReadOnly = true;
			this.txtAllMoney.Size = new Size(695, 22);
			this.txtAllMoney.TabIndex = 46;
			this.txtAllMoney.TextAlign = HorizontalAlignment.Right;
			this.btnSave.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left);
			this.btnSave.Enabled = false;
			this.btnSave.FlatAppearance.BorderColor = Color.FromArgb(255, 128, 255);
			this.btnSave.FlatStyle = FlatStyle.Flat;
			this.btnSave.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnSave.Location = new System.Drawing.Point(109, 568);
			this.btnSave.Name = "btnSave";
			this.btnSave.Size = new Size(90, 26);
			this.btnSave.TabIndex = 47;
			this.btnSave.Text = "Lưu lại  [ F6 ]";
			this.btnSave.UseVisualStyleBackColor = true;
			this.btnSave.Click += new EventHandler(this.btnSave_Click);
			this.btnEdit.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left);
			this.btnEdit.FlatAppearance.BorderColor = Color.FromArgb(255, 128, 255);
			this.btnEdit.FlatStyle = FlatStyle.Flat;
			this.btnEdit.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnEdit.Location = new System.Drawing.Point(7, 568);
			this.btnEdit.Name = "btnEdit";
			this.btnEdit.Size = new Size(100, 26);
			this.btnEdit.TabIndex = 48;
			this.btnEdit.Text = "Cập nhật  [ F5 ]";
			this.btnEdit.UseVisualStyleBackColor = true;
			this.btnEdit.Click += new EventHandler(this.btnEdit_Click);
			this.btnExportToExcel.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left);
			this.btnExportToExcel.Enabled = false;
			this.btnExportToExcel.FlatAppearance.BorderColor = Color.FromArgb(255, 128, 255);
			this.btnExportToExcel.FlatStyle = FlatStyle.Flat;
			this.btnExportToExcel.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnExportToExcel.Location = new System.Drawing.Point(305, 568);
			this.btnExportToExcel.Name = "btnExportToExcel";
			this.btnExportToExcel.Size = new Size(102, 26);
			this.btnExportToExcel.TabIndex = 49;
			this.btnExportToExcel.Text = "Xuất file Excel";
			this.btnExportToExcel.UseVisualStyleBackColor = true;
			this.btnExportToExcel.Click += new EventHandler(this.btnExportToExcel_Click);
			this.bindingNavigator1.AddNewItem = null;
			this.bindingNavigator1.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right);
			this.bindingNavigator1.AutoSize = false;
			this.bindingNavigator1.BackColor = SystemColors.ButtonFace;
			this.bindingNavigator1.CountItem = this.bindingNavigatorCountItem;
			this.bindingNavigator1.CountItemFormat = "/ {0}";
			this.bindingNavigator1.DeleteItem = null;
			this.bindingNavigator1.Dock = DockStyle.None;
			this.bindingNavigator1.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 163);
			this.bindingNavigator1.GripStyle = ToolStripGripStyle.Hidden;
			this.bindingNavigator1.Items.AddRange(new ToolStripItem[]
			{
				this.bindingNavigatorMoveFirstItem,
				this.bindingNavigatorMovePreviousItem,
				this.bindingNavigatorSeparator,
				this.bindingNavigatorPositionItem,
				this.bindingNavigatorCountItem,
				this.bindingNavigatorSeparator1,
				this.bindingNavigatorMoveNextItem,
				this.bindingNavigatorMoveLastItem,
				this.bindingNavigatorSeparator2
			});
			this.bindingNavigator1.Location = new System.Drawing.Point(7, 539);
			this.bindingNavigator1.MoveFirstItem = this.bindingNavigatorMoveFirstItem;
			this.bindingNavigator1.MoveLastItem = this.bindingNavigatorMoveLastItem;
			this.bindingNavigator1.MoveNextItem = this.bindingNavigatorMoveNextItem;
			this.bindingNavigator1.MovePreviousItem = this.bindingNavigatorMovePreviousItem;
			this.bindingNavigator1.Name = "bindingNavigator1";
			this.bindingNavigator1.PositionItem = this.bindingNavigatorPositionItem;
			this.bindingNavigator1.RenderMode = ToolStripRenderMode.Professional;
			this.bindingNavigator1.Size = new Size(887, 25);
			this.bindingNavigator1.TabIndex = 145;
			this.bindingNavigator1.Text = "bindingNavigator1";
			this.bindingNavigatorCountItem.Name = "bindingNavigatorCountItem";
			this.bindingNavigatorCountItem.Size = new Size(28, 22);
			this.bindingNavigatorCountItem.Text = "/ {0}";
			this.bindingNavigatorCountItem.ToolTipText = "Total number of items";
			this.bindingNavigatorMoveFirstItem.DisplayStyle = ToolStripItemDisplayStyle.Image;
//			//this.bindingNavigatorMoveFirstItem.Image = (Image)componentResourceManager.GetObject("bindingNavigatorMoveFirstItem.Image");
			this.bindingNavigatorMoveFirstItem.Name = "bindingNavigatorMoveFirstItem";
			this.bindingNavigatorMoveFirstItem.RightToLeftAutoMirrorImage = true;
			this.bindingNavigatorMoveFirstItem.Size = new Size(23, 22);
			this.bindingNavigatorMoveFirstItem.Text = "Move first";
			this.bindingNavigatorMovePreviousItem.DisplayStyle = ToolStripItemDisplayStyle.Image;
            ////this.bindingNavigatorMovePreviousItem.Image = (Image)componentResourceManager.GetObject("bindingNavigatorMovePreviousItem.Image");
			this.bindingNavigatorMovePreviousItem.Name = "bindingNavigatorMovePreviousItem";
			this.bindingNavigatorMovePreviousItem.RightToLeftAutoMirrorImage = true;
			this.bindingNavigatorMovePreviousItem.Size = new Size(23, 22);
			this.bindingNavigatorMovePreviousItem.Text = "Move previous";
			this.bindingNavigatorSeparator.Name = "bindingNavigatorSeparator";
			this.bindingNavigatorSeparator.Size = new Size(6, 25);
			this.bindingNavigatorPositionItem.AccessibleName = "Position";
			this.bindingNavigatorPositionItem.AutoSize = false;
			this.bindingNavigatorPositionItem.Name = "bindingNavigatorPositionItem";
			this.bindingNavigatorPositionItem.Size = new Size(50, 23);
			this.bindingNavigatorPositionItem.Text = "0";
			this.bindingNavigatorPositionItem.ToolTipText = "Current position";
			this.bindingNavigatorSeparator1.Name = "bindingNavigatorSeparator1";
			this.bindingNavigatorSeparator1.Size = new Size(6, 25);
			this.bindingNavigatorMoveNextItem.DisplayStyle = ToolStripItemDisplayStyle.Image;
            ////this.bindingNavigatorMoveNextItem.Image = (Image)componentResourceManager.GetObject("bindingNavigatorMoveNextItem.Image");
			this.bindingNavigatorMoveNextItem.Name = "bindingNavigatorMoveNextItem";
			this.bindingNavigatorMoveNextItem.RightToLeftAutoMirrorImage = true;
			this.bindingNavigatorMoveNextItem.Size = new Size(23, 22);
			this.bindingNavigatorMoveNextItem.Text = "Move next";
			this.bindingNavigatorMoveLastItem.DisplayStyle = ToolStripItemDisplayStyle.Image;
            ////this.bindingNavigatorMoveLastItem.Image = (Image)componentResourceManager.GetObject("bindingNavigatorMoveLastItem.Image");
			this.bindingNavigatorMoveLastItem.Name = "bindingNavigatorMoveLastItem";
			this.bindingNavigatorMoveLastItem.RightToLeftAutoMirrorImage = true;
			this.bindingNavigatorMoveLastItem.Size = new Size(23, 22);
			this.bindingNavigatorMoveLastItem.Text = "Move last";
			this.bindingNavigatorSeparator2.Name = "bindingNavigatorSeparator2";
			this.bindingNavigatorSeparator2.Size = new Size(6, 25);
			this.btnHelp.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left);
			this.btnHelp.Enabled = false;
			this.btnHelp.FlatAppearance.BorderColor = Color.FromArgb(255, 128, 255);
			this.btnHelp.FlatStyle = FlatStyle.Flat;
			this.btnHelp.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnHelp.Location = new System.Drawing.Point(409, 568);
			this.btnHelp.Name = "btnHelp";
			this.btnHelp.Size = new Size(142, 26);
			this.btnHelp.TabIndex = 146;
			this.btnHelp.Text = "Hướng dẫn nhập liệu";
			this.btnHelp.UseVisualStyleBackColor = true;
			this.btnHelp.Click += new EventHandler(this.btnHelp_Click);
			base.AutoScaleDimensions = new SizeF(7f, 15f);
			//base.AutoScaleMode = AutoScaleMode.Font;
			this.BackColor = Color.White;
			base.ClientSize = new Size(900, 600);
			base.Controls.Add(this.btnHelp);
			base.Controls.Add(this.btnExportToExcel);
			base.Controls.Add(this.btnEdit);
			base.Controls.Add(this.btnSave);
			base.Controls.Add(this.txtAllMoney);
			base.Controls.Add(this.btnPrint);
			base.Controls.Add(this.btnClose);
			base.Controls.Add(this.dgvProduct);
			base.Controls.Add(this.groupBox1);
			base.Controls.Add(this.bindingNavigator1);
			this.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 0);
			//base.Icon = (System.Drawing.Icon)componentResourceManager.GetObject("$this.Icon");
			//base.Icon = (Icon)componentResourceManager.GetObject("$this.Icon");
			base.KeyPreview = true;
			base.Name = "frmDebtFirstBalancer";
			base.ShowInTaskbar = false;
			base.StartPosition = FormStartPosition.CenterScreen;
			this.Text = "CẬP NHẬT CÔNG NỢ ĐẦU KỲ";
			base.WindowState = FormWindowState.Maximized;
			base.Load += new EventHandler(this.frmDebtNeedIn_Load);
			base.KeyDown += new KeyEventHandler(this.frmDebtNeedIn_KeyDown);
			this.groupBox1.ResumeLayout(false);
			this.groupBox1.PerformLayout();
			((ISupportInitialize)this.dgvProduct).EndInit();
			((ISupportInitialize)this.bindingNavigator1).EndInit();
			this.bindingNavigator1.ResumeLayout(false);
			this.bindingNavigator1.PerformLayout();
			base.ResumeLayout(false);
			base.PerformLayout();
		}
		public frmDebtFirstBalancer()
		{
			this.InitializeComponent();
			Program.strConnectionString = this.objFunc.strConnectionString;
		}
		private void frmDebtNeedIn_Load(object sender, EventArgs e)
		{
			this.cbbObject.SelectedIndex = 0;
			this.getData();
			this.isPostBack = true;
		}
		private void getData()
		{
			DataTable dataTable = new DataTable();
			DataColumn column = new DataColumn("CID", typeof(string));
			DataColumn column2 = new DataColumn("PID", typeof(string));
			DataColumn column3 = new DataColumn("Name", typeof(string));
			DataColumn column4 = new DataColumn("Address", typeof(string));
			DataColumn column5 = new DataColumn("Phone", typeof(string));
			DataColumn column6 = new DataColumn("Money", typeof(string));
			dataTable.Columns.Add(column);
			dataTable.Columns.Add(column2);
			dataTable.Columns.Add(column3);
			dataTable.Columns.Add(column4);
			dataTable.Columns.Add(column5);
			dataTable.Columns.Add(column6);
			SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
			sqlConnection.Open();
			SqlCommand sqlCommand = sqlConnection.CreateCommand();
			string str = "";
			if (this.txtSearch.Text.Trim() != "")
			{
				str = " AND Name LIKE N'%" + this.txtSearch.Text + "%' ";
			}
			if (this.cbbObject.SelectedIndex == 1)
			{
				sqlCommand.CommandText = "SELECT * FROM [TabPartner] WHERE [IsProvider] = 1 " + str + " ORDER BY [Name]";
			}
			else
			{
				sqlCommand.CommandText = "SELECT * FROM [TabPartner] WHERE [IsCustomer] = 1 " + str + " ORDER BY [Name]";
			}
			SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
			double num = 0.0;
			while (sqlDataReader.Read())
			{
				double num2 = (double)float.Parse(sqlDataReader["firstBalance"].ToString());
				num += num2;
				dataTable.Rows.Add(new object[]
				{
					sqlDataReader["CusID"].ToString(),
					sqlDataReader["ProID"].ToString(),
					sqlDataReader["Name"].ToString().ToUpper(),
					sqlDataReader["Address"].ToString(),
					sqlDataReader["Phone"].ToString(),
					string.Format(Program.lenAffterDecimal, num2)
				});
			}
			sqlDataReader.Close();
			sqlConnection.Close();
			sqlConnection.Dispose();
			this.btnPrint.Enabled = true;
			this.objTable = dataTable;
			BindingSource bindingSource = new BindingSource();
			bindingSource.DataSource = this.objTable;
			this.bindingNavigator1.BindingSource = bindingSource;
			this.dgvProduct.DataSource = bindingSource;
			this.txtAllMoney.Text = string.Format(Program.lenAffterDecimal, num);
			if (this.dgvProduct.Rows.Count > 0)
			{
				this.btnPrint.Enabled = true;
				this.btnExportToExcel.Enabled = true;
			}
			else
			{
				this.btnPrint.Enabled = false;
				this.btnExportToExcel.Enabled = false;
			}
		}
		private void btnClose_Click(object sender, EventArgs e)
		{
			if (!this.btnEdit.Enabled)
			{
				if (MessageBox.Show("Bạn có muốn lưu lại sự thay đổi số dư đầu kỳ không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
				{
					this.btnSave.PerformClick();
				}
			}
			base.Close();
		}
		private void frmDebtNeedIn_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.KeyCode == Keys.Escape)
			{
				base.Close();
			}
			else
			{
				if (e.KeyCode == Keys.F5)
				{
					this.btnEdit.PerformClick();
				}
				else
				{
					if (e.KeyCode == Keys.F6)
					{
						this.btnSave.PerformClick();
					}
					else
					{
						if (e.KeyCode == Keys.F7)
						{
							this.btnPrint.PerformClick();
						}
					}
				}
			}
		}
		private void ckbProviderAll_CheckedChanged(object sender, EventArgs e)
		{
			this.getData();
		}
		private void btnEdit_Click(object sender, EventArgs e)
		{
			this.btnSave.Enabled = true;
			this.btnEdit.Enabled = false;
			this.dgvProduct.ReadOnly = false;
			this.dgvProduct.SelectionMode = DataGridViewSelectionMode.CellSelect;
		}
		private void btnSave_Click(object sender, EventArgs e)
		{
			for (int i = 0; i < this.dgvProduct.Rows.Count; i++)
			{
				this.objPartner.getFistBalanceCustomerUpdate(this.dgvProduct.Rows[i].Cells["CID"].Value.ToString(), this.dgvProduct.Rows[i].Cells["Money"].Value.ToString().Replace(",", ""));
			}
			this.btnSave.Enabled = false;
			this.btnEdit.Enabled = true;
			this.dgvProduct.ReadOnly = true;
			this.dgvProduct.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
		}
		private void btnPrint_Click(object sender, EventArgs e)
		{
			frmRepDebtFirstBalancer.objTable = new DataTable();
			frmDebtFirstBalancerView frmDebtFirstBalancerView = new frmDebtFirstBalancerView();
			frmRepDebtFirstBalancer.objTable = this.objTable;
			frmDebtFirstBalancerView.totalMoney = this.txtAllMoney.Text;
			frmDebtFirstBalancerView.ShowDialog();
			try
			{
				this.dgvProduct.Columns["TT"].Visible = false;
			}
			catch
			{
			}
		}
		private void btnExportToExcel_Click(object sender, EventArgs e)
		{
			try
			{
				frmRepDebtFirstBalancer.objTable = new DataTable();
				frmRepDebtFirstBalancer.objTable = this.objTable;
				ActiveReport3 activeReport = new frmRepDebtFirstBalancer();
				activeReport.Run();
				XlsExport xlsExport = new XlsExport();
				SaveFileDialog saveFileDialog = new SaveFileDialog();
				saveFileDialog.ShowDialog();
				string text = saveFileDialog.FileName;
				if (text != "")
				{
					if (!text.ToUpper().Contains(".XLS"))
					{
						text += ".xls";
					}
					xlsExport.Export(activeReport.Document, text);
					MessageBox.Show("Hệ thống đã hoàn thành việc xuất dữ liệu ra file Excel", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
				}
				else
				{
					MessageBox.Show("Bạn chưa chọn đường dẫn và tên file cần xuất!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				}
			}
			catch
			{
			}
		}
		private void cbbObject_SelectedIndexChanged(object sender, EventArgs e)
		{
			if (this.isPostBack)
			{
				this.getData();
			}
		}
		private void txtSearch_TextChanged(object sender, EventArgs e)
		{
			if (this.txtSearch.Text.Trim() != "")
			{
				this.getData();
			}
		}
		private void btnHelp_Click(object sender, EventArgs e)
		{
			frmUserGuide frmUserGuide = new frmUserGuide();
			frmUserGuide.ShowDialog();
		}
	}
}
